import ora from "ora";
import { App } from "../types/app";
import { Config } from "../types/config";
import { CreateUsePlugin } from "./plugin/usePlugin";
import { initApp } from "./process/initApp";
import { resolvePlugins } from "./resolve/resolvePlugins";
import { resolveOptionSshList } from "./resolve/resolveOptionSshList";
import { resolveOptionUploadList } from "./resolve/resolveOptionUploadList";
import { clearFiles } from "./setup/clearFiles";

export function createApp(config: Config) {
    const uploadList = resolveOptionUploadList(config);
    const sshList = resolveOptionSshList(config);
    const plugins = resolvePlugins(config);

    const app = {
        uploadList,
        sshList,
        plugins,
        spinner: ora(),
    } as App;

    app.use = CreateUsePlugin(app);
    app.init = initApp.bind(null, app);
    app.clear = clearFiles.bind(null);

    return app;
}
